﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace XclusiveService.Models
{
    public class ClientRepository : IClientRepository
    {
        //Getting all the Clients
        public IEnumerable<Client> GetAllClient()
        {
            return DatabaseManager.GetAllClient().Cast<Client>();
        }

        //Getting a Client by company_name
        public Client GetClientByCompanyName(string company_name)
        {
            return DatabaseManager.GetClientByCompanyName(company_name);
        }

        //Creating a Client (POST)
        public Client CreateClient(Client c)
        {
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }

            if (DatabaseManager.CreateClient(c) == 0)
            {
                return null;
            }
            else
            {
                return c;
            }
        }

        //Update a Client (PUT)
        public bool UpdateClient(Client c)
        {
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }

            if (DatabaseManager.UpdateClient(c) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        //Deleting a Client
        public void DeleteClient(string company_name)
        {
            DatabaseManager.DeleteClient(company_name);
        }
    }
}